﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ehitisedParingType", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(EhitisedParingType))]
    public class EhitisedParingTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEhitisedParingType clazz;
        
        public EhitisedParingTypeSerializer(IEhitisedParingType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.KinnistuData!=null) {
                Writer.WriteStartElement("kinnistu_data");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("string", "http://www.w3.org/2001/XMLSchema", clazz.KinnistuData.Count);
                if (((clazz.KinnistuData == null) 
                            || (clazz.KinnistuData.Count < 1m))) {
                    throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                }
                for (int x = 0; ((clazz.KinnistuData != null) 
                            && (x < clazz.KinnistuData.Count)); x = (x + 1)) {
                    Writer.WriteStartElement("item");
                    if (clazz.KinnistuData[x]!=null) {
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KinnistuData[x]))).ToString());
                    }
                    else {
                        Writer.WriteAttributeString("xsi", "nil", null, "1");
                    }
                    Writer.WriteEndElement();
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kinnistu_data") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ehitisedParingType>kinnistu_data");
                }
                clazz.KinnistuData = new System.Collections.Generic.List<System.String>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kinnistu_data");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.LocalName=="item") {
                            if ((Reader.IsElementNil() == false)) {
                                clazz.KinnistuData.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("item")).Value);
                            }
                            else {
                                clazz.KinnistuData.Add(null);
                                Reader.Skip();
                            }
                        }
                        else {
                            throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">item", Reader.LocalName);
                        }
                    }
                    if ((clazz.KinnistuData.Count < 1m)) {
                        throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
